import {MessageBox} from "element-ui";

export function warnConfirm(msg="确定该操作吗？") {
    return MessageBox.confirm(msg, {type: "warning"})
}
export function checkShake(callback) {
    if (window.DeviceMotionEvent) {
        let speed = 20;    // 用来判定的加速度阈值，太大了则很难触发
        let x, y, z, lastX, lastY, lastZ;
        x = y = z = lastX = lastY = lastZ = 0;
        window.addEventListener('devicemotion', function (event) {
            const acceleration: any = event.accelerationIncludingGravity;
            x = acceleration.x;
            y = acceleration.y;
            if (Math.abs(x - lastX) > speed || Math.abs(y - lastY) > speed) {
                callback && callback();
            }
            lastX = x;
            lastY = y;
        });
    }
}
